package cn.cycleif.app.controller;

import cn.cycleif.app.domain.dto.TagAddDTO;
import cn.cycleif.app.service.TagService;
import cn.cycleif.util.R;
import cn.dev33.satoken.annotation.SaCheckOr;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaIgnore;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Date: 25/2/6-17:05
 * @Desc:
 */
@RequestMapping("/api/tag")
@RestController
@Tag(name = "标签管理")
public class TagController {

  @Autowired
  private TagService tagService;

  @PostMapping()
  @Operation(summary = "新增标签")
  @SaCheckOr(
      role = @SaCheckRole("staff"),
      permission = @SaCheckPermission("tag.add")
  )
  public R<String> addTag(@RequestBody TagAddDTO tag) {
    return tagService.addTag(tag);
  }

  @PutMapping()
  @Operation(summary = "修改标签")
  @SaCheckOr(
      role = @SaCheckRole("staff"),
      permission = @SaCheckPermission("tag.update")
  )
  public R<String> updateTag(@RequestBody cn.cycleif.entity.Tag tag) {
    return tagService.updateTag(tag);
  }

  @DeleteMapping("/{id}")
  @Operation(summary = "删除标签")
  @SaCheckOr(
      role = @SaCheckRole("staff"),
      permission = @SaCheckPermission("tag.del")
  )
  public R<String> deleteTag(@PathVariable("id") Integer id) {
    return tagService.deleteTag(id);
  }

  @GetMapping("/{id}")
  @Operation(summary = "获取标签")
  @SaIgnore
  public R<cn.cycleif.entity.Tag> getTag(@PathVariable("id") Integer id) {
    return tagService.getTag(id);
  }
  @GetMapping("/name/{id}")
  @Operation(summary = "获取标签")
  @SaIgnore
  public R<cn.cycleif.entity.Tag> getTagByName(@PathVariable("id") String id) {
    return tagService.getTagByName(id);
  }

  @GetMapping("/list")
  @Operation(summary = "获取标签列表")
  @SaIgnore
  public R<Object> getPage(
      @RequestParam("order") String order
  ) {
    return tagService.getPage(order);
  }

  @GetMapping("/listAll")
  @Operation(summary = "获取全部标签精简信息")
  @SaIgnore
  public R<Object> getListAll() {
    return tagService.getListAll();
  }
}
